#include<bits/stdc++.h>
using namespace std;

int main() {
	freopen("deteck.in", "r", stdin);
	freopen("deteck.out", "w", stdout);
	int t;
	cin >> t;
	while(t--) {
		int n, m, l, v;
		int t;
		cin >> n >> m >> l >> v;
		int cad[n], cav[n], caa[n];
		int long_max = INT_MIN;
		bool A = true;
		for(int i = 0; i < n; i++) {
			scanf("%d %d %d", &cad[i], &cav[i], &caa[i]);
			if(caa[i] != 0) {
				A = false;
			}
		}
		int p[m];
		for(int i = 0; i < m; i++) {
			scanf("%d", &p[i]);
			long_max = max(long_max, p[i]);
		}
		if(A) {
			int cnt = 0;
			for(int i = 0; i < n; i++) {
				if(long_max < cad[i]) continue;
				if(cav[i] > v) {
					cnt++;
				}
			}
			cout << cnt << ' ' << ((cnt == 0) ? m : m - 1) << endl;
		}
		else cout << 0 << ' ' << 0 << endl;
	}
	
	return 0;
	}
